<?php

defined('_JEXEC') or die;

$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$user = JFactory::getUser();
$session = JFactory::getSession();

$this->language = $doc->language;
$this->direction = $doc->direction;

$params = $app->getTemplate(true)->params;

$option = $app->input->getCmd('option', '');
$view = $app->input->getCmd('view', '');
$layout = $app->input->getCmd('layout', '');
$task = $app->input->getCmd('task', '');
$itemid = $app->input->getCmd('Itemid', '');
$sitename = $app->get('sitename');

$doc->setHtml5(true);

if ($task == "edit" || $layout == 'form') {
    $fullWidth = 1;
}
else {
    $fullWidth = 0;
}
$getArray = $app->input->getArray();
$applist = $getArray['applist'];
$appverSion = $getArray['verSion'];
$appchannels = $getArray['channels'];
$doc->setTitle('AdGyde - Console');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/jquery.min.js');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/bootstrap.min.js');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/charthelp.js');
//echarts
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/echarts.min.js');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/newline-echarts.js');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/layer/layer.js');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/ajaxForm.js');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/common.js');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/pikaday.js');

$doc->addStyleSheet($this->baseurl . '/templates/' . $this->template . '/css/bootstrap.min.css');
$doc->addStyleSheet($this->baseurl . '/templates/' . $this->template . '/css/bootstrap-theme.min.css');
$doc->addStyleSheet($this->baseurl . '/templates/' . $this->template . '/css/ie10-viewport-bug-workaround.css');
$doc->addStyleSheet($this->baseurl . '/templates/' . $this->template . '/css/template.css');
$doc->addStyleSheet($this->baseurl . '/templates/' . $this->template . '/css/pikaday.css');

// disable builtin bootstrap2.x
$headData = $doc->getHeadData();
$scripts = $headData['scripts'];
unset($scripts[JUri::root(true) . '/media/jui/js/jquery.min.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/bootstrap.min.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/jquery-noconflict.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/jquery-migrate.min.js']);
$headData['scripts'] = $scripts;
$doc->setHeadData($headData);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language ?>" lang="<?php echo $this->language ?>" dir="<?php echo $this->direction ?>">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
    <jdoc:include type="head" />
</head>
<body>
<div id="console-head">
    <span class="formlogo"><a href="/index.php"></a></span>
    <div class="headlink">
        <a href="/index.php/getting-start"><span class="glyphicon glyphicon-book"></span>Documents</a>
        <span id="user" class="colwhite pre_pos"><i class="glyphicon glyphicon-user"></i> <?php echo $user->username ?>
            <div class="adminshow">
                <ul>
                    <li><a href="/index.php/user-profile">Profile</a></li>
                    <li><a href="/index.php?option=com_users&view=login&layout=logout&task=user.menulogout&Itemid=152">Logout</a></li>
                </ul>
            </div>
        </span>
    </div>
    <div style="clear:both" />
</div>
<div id="console-toolbar">
    <div class="toolbarlf fl">
        <div class="dropdown">
        	<button class="btn btn-revision dropdown-toggle fontsize16" type="button" id="appMenu"
        			data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"
        			style="min-width:120px;align:left">
        		<?php
        			if ($session->get('appName')) {
        				echo $session->get('appName');
        			}
        			else {
        				echo 'All applications';
        			}
        		?>
        		<span class="arrow-x"></span>
        	</button>
        	<ul class="dropdown-menu" aria-labelledby="appMenu">
        		<li><a href="/index.php?option=com_console&task=toAppSession&app_id=-1">All applications</a></li>
        		<?php foreach($applist as $app): ?>
        		<li><a href="/index.php?option=com_console&task=toAppSession&app_id=<?php echo $app->id;?>"><?php echo $app->name;?></a></li>
        		<?php endforeach; ?>
        	</ul>
        </div>
    </div>

	<div class="loading fl">
		<img id="ajax-loading" src="/templates/ppspconsole/images/loading.gif" width="48px" height="48px"/>
	</div>

    <div class="toolbarg collan fr">
        <div class="txt-group pre_pos xtx-gpouptime">
          <div class="inputtext"><input type="text" class="form-control ip-revision" value="<?php if($session->get('appstartime') && $session->get('appendtime')){echo $session->get('appstartime').' - '.$session->get('appendtime');} ?>" placeholder="<?php if($session->get('appstartime') && $session->get('appendtime')){echo $session->get('appstartime').' - '.$session->get('appendtime');} else { echo date('M d, Y',strtotime("-7 day")) .' - '.date('M d, Y',time()); } ?>" /><span class="glyphicon glyphicon-calendar"></span></div>
          <ul class="dropdown-menu">
            <li class="text-c pd_tp_bt"><input type="text" class="form-control startime"  id="datepicker" value="<?php echo $session->get('appstartime');?>" />
                - <input type="text" id="datepicker1" class="form-control endtime" value="<?php echo $session->get('appendtime');?>" /></li>
            <li class="bgf7 text-r"><button type="button" class="btn btn-primary apptime">OK</button><button type="button" class="cancelbtn btn btn-default">Cancel</button></li>
          </ul>
        </div>
    </div>
    <div class="toolbarg collan fr">
		<div class="dropdown" style="margin-right:8px">
        	<button class="btn btn-revision dropdown-toggle fontsize16 btn-wd" type="button" id="channelMenu"
        			data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
        		<?php
        			if ($session->get('appchannel')) {
        				echo $session->get('appchannel');
        			}
        			else {
        				echo 'All channels';
        			}
        		?>
        		<span class="arrow-x"></span>
        	</button>
        	<ul class="dropdown-menu" aria-labelledby="channelMenu">
        		<li><a href="/index.php?option=com_console&task=toAppSession&appchannel=all">All channels</a></li>
        		<?php if ($appchannels->result): ?>
        		<?php foreach($appchannels->result as $channel): ?>
        		<li><a href="/index.php?option=com_console&task=toAppSession&appchannel=<?php echo $channel;?>"><?php echo $channel == '' ? 'default' : $channel ?></a></li>
        		<?php endforeach; ?>
        		<?php endif?>
        	</ul>
        </div>
    </div>

    <div class="toolbarg collan fr">
		<div class="dropdown" style="margin-right:8px">
        	<button class="btn btn-revision dropdown-toggle fontsize16 btn-wd" type="button" id="versionMenu"
        			data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
        		<?php
        			if ($session->get('appver')) {
        				echo $session->get('appver');
        			}
        			else {
        				echo 'All versions';
        			}
        		?>
        		<span class="arrow-x"></span>
        	</button>
        	<ul class="dropdown-menu" aria-labelledby="versionMenu">
        		<li><a href="/index.php?option=com_console&task=toAppSession&appver=all">All versions</a></li>
        		<?php foreach($appverSion->result as $version): ?>
        		<li><a href="/index.php?option=com_console&task=toAppSession&appver=<?php echo $version ?>"><?php echo $version ?></a></li>
        		<?php endforeach; ?>
        	</ul>
        </div>
    </div>

    <div class="clear"></div>
</div>
<div id="console-content">
    <div id="console-menu">
        <ul id="menu-ul">
            <li>
            	<h3 <?php if(strtolower($view) == 'overview'):?>class="selected"<?php endif;?>><a href="/index.php?option=com_console&view=overview&Itemid=<?php echo $itemid ?>"><span class="res-icon res-overview"></span>Overview</a></h3>
            </li>
            <li>
                <h3><a href="javascript:void(0)"><span class="res-icon res-acquisition"></span>Acquisition</a><i class="arrowright"></i></h3>
                <div class="">
                    <p><a href="/index.php?option=com_console&view=newusers&Itemid=127&task=NewUsers" <?php if($view == 'newusers'):?>class="selected"<?php endif;?>>New Users</a></p>
                    <p><a href="/index.php?option=com_console&view=usersflow&Itemid=127&task=UsersFlow" <?php if($view == 'usersflow'):?>class="selected"<?php endif;?>>Users Flow</a></p>
                    <p><a href="/index.php?option=com_console&view=campaignperformance&Itemid=127&task=CampaignPerformance" <?php if($view == 'campaignperformance'):?>class="selected"<?php endif;?>>Campaign Performance</a></p>
                    <p><a href="/index.php?option=com_console&view=retargeting&Itemid=127&task=ReTargeting" <?php if($view == 'retargeting'):?>class="selected"<?php endif;?>>Re-Targeting</a></p>
                    <p><a href="/index.php?option=com_console&view=cohort&Itemid=127&task=Cohort" <?php if($view == 'cohort'):?>class="selected"<?php endif;?>>Cohort</a></p>
                    <p><a href="/index.php?option=com_console&view=returningusers&Itemid=127&task=ReturningUsers" <?php if($view == 'returningusers'):?>class="selected"<?php endif;?>>Returning Users</a></p>
                </div>
            </li>
            <li>
                <h3><a href="javascript:void(0)"><span class="res-icon res-audience"></span>Audience</a><i class="arrowright"></i></h3>
                <div class="">
                    <p><a href="/index.php?option=com_console&view=activeusers&task=ActiveUsers&Itemid=<?php echo $itemid ?>" <?php if($view == 'activeusers'):?>class="selected"<?php endif;?>>Active Users</a></p>
                    <p><a href="/index.php?option=com_console&view=session&Itemid=127&task=Session" <?php if($view == 'session'):?>class="selected"<?php endif;?> >Sessions</a></p>
                    <p><a href="/index.php?option=com_console&view=sessionduration&Itemid=127&task=SessionDuration" <?php if($view == 'sessionduration'):?>class="selected"<?php endif;?>>Avg Session Duration</a></p>
                    <p><a href="/index.php?option=com_console&view=devices&Itemid=127&task=Devices" <?php if($view == 'devices'):?>class="selected"<?php endif;?> >Devices</a></p>
                    <p><a href="/index.php?option=com_console&view=networks&Itemid=127&task=Networks" <?php if($view == 'networks'):?>class="selected"<?php endif;?> >Networks</a></p>
                    <p><a href="/index.php?option=com_console&view=operators&Itemid=127&task=Operators" <?php if($view == 'operators'):?>class="selected"<?php endif;?> >Operators</a></p>
                    <p><a href="/index.php?option=com_console&view=eventfrequency&Itemid=127&task=EventFrequency" <?php if($view == 'eventfrequency'):?>class="selected"<?php endif;?> >Event Frequency</a></p>
                    <p><a href="/index.php?option=com_console&view=CountingEvent&Itemid=127&task=CountingEvent" <?php if($view == 'CountingEvent'):?>class="selected"<?php endif;?>>Counting Events</a></p>
                    <p><a href="/index.php?option=com_console&view=computingevent&Itemid=127&task=ComputingEvent" <?php if($view == 'computingevent'):?>class="selected"<?php endif;?> >Computing Events</a></p>
                    <p><a href="/index.php?option=com_console&view=conversion&Itemid=127&task=Conversion" <?php if($view == 'conversion'):?>class="selected"<?php endif;?> >Conversion</a></p>
                </div>
            </li>
            <li>
                <h3><a href="javascript:void(0)"><span class="res-icon res-revenue"></span>Revenue</a><i class="arrowright"></i></h3>
                <div class="">
                    <p><a href="/index.php?option=com_console&view=dailyrevenue&Itemid=127&task=DailyRevenue" <?php if($view == 'dailyrevenue'):?>class="selected"<?php endif;?>>Daily Revenue</a></p>
                </div>
            </li>
            <li>
                <h3><a href="javascript:void(0)"><span class="res-icon res-setup"></span>Setup</a><i class="arrowright"></i></h3>
                <div class="">
                    <p><a href="/index.php?option=com_console&view=applications&Itemid=127&task=Applications" <?php if($view == 'applications'):?>class="selected"<?php endif;?> >Applications</a></p>
                    <p><a href="/index.php?option=com_console&view=testphones&Itemid=127&task=TestPhones" <?php if($view == 'testphones'):?>class="selected"<?php endif;?> >Test Phones</a></p>
                    <p><a href="/index.php?option=com_console&view=events&Itemid=127&task=Events" <?php if($view == 'events'):?>class="selected"<?php endif;?> >Events</a></p>
                    <p><a href="/index.php?option=com_console&view=eventfunnel&Itemid=127&task=EventFunnel" <?php if($view == 'eventfunnel'):?>class="selected"<?php endif;?> >Event Funnel</a></p>
                    <p><a href="/index.php?option=com_console&view=campaigntracking&Itemid=127&task=CampaignTracking" <?php if($view == 'campaigntracking'):?>class="selected"<?php endif;?> >Campaign Tracking</a></p>
                    <p><a href="/index.php?option=com_console&view=deeplink&Itemid=127&task=DeepLink" <?php if($view == 'deeplink'):?>class="selected"<?php endif;?> >Deep Link</a></p>
                </div>
            </li>
            <li>
                <h3><a href="javascript:void(0)"><span class="res-icon res-export"></span>Export</a><i class="arrowright"></i></h3>
                <div class="">
                    <p><a href="/index.php?option=com_console&view=reports&Itemid=127&task=Reports" <?php if($view == 'reports'):?>class="selected"<?php endif;?>>Reports</a></p>
                    <p><a href="/index.php?option=com_console&view=reportsbywebservice&Itemid=127&task=ReportsbyWEBService" <?php if($view == 'reportsbywebservice'):?>class="selected"<?php endif;?>>Reports by WEB Service</a></p>
                </div>
            </li>
        </ul>
    </div>
    <div id="console-ws">
        <jdoc:include type="component"/>
    </div>
    <div class="clear"></div>
</div>
<div id="console-foot">Copyright @ 2015-2016 (c) AdGyde</div>
<script type="text/javascript">
    $(function(){
        function onresizeheight(){
            $("#console-menu").css({"height":$(window).height()-$("#console-head").height()-$("#console-toolbar").height()-1-$("#console-foot").height()}); //自动调整页面高度
            $("#console-ws").css({"height":$(window).height()-$("#console-head").height()-$("#console-toolbar").height()-1-$("#console-foot").height()}); //自动调整页面高度
        }
        window.onresize = onresizeheight;
        onresizeheight();
        $("#menu-ul li").find("a.selected").parent().parent().show();
        $("#menu-ul li").find("a.selected").parent().parent().parent().find("i").addClass("xz90");
        $("#menu-ul h3").click(function(){
            if($(this).parent().find("div").is(":hidden")){
                $("#menu-ul").find("div").fadeOut(50);
                $("#menu-ul li").find("h3").removeClass("selected");
                $(this).addClass("selected");
                $(this).parent().find("div").slideToggle("slow");
                $("#menu-ul li").find("i").removeClass("xz90");
                $(this).find("i").removeClass("xzf90");
                $(this).find("i").addClass("xz90");
            }else{
                $(this).parent().find("div").slideToggle("slow");
                $(this).find("i").removeClass("xz90");
                $(this).find("i").addClass("xzf90");
            }

        });
        $("#user").hover(function(){
            $(this).find("div").show();
        },function(){
            $(this).find("div").hide();
        });
        $(".inputtext input").focus(function(){
            var thismenu=$(this).parent().parent().find(".dropdown-menu");
            $(".dropdown-menu").hide();
            thismenu.show();
        });
        $(".cancelbtn").click(function(){
            $(this).parent().parent().hide();
        });

        $('.channel').click(function(){
            var appchannel = $('.appchannel:checked').val();
            window.location.href="/index.php?option=com_console&task=toAppSession&appchannel="+appchannel;
        });

        $('.appversion').click(function(){
            var appversion = $('.appver:checked').val();
            window.location.href="/index.php?option=com_console&task=toAppSession&appver="+appversion;
        });

        $('.apptime').click(function(){
            var appstartime = $('.startime').val();
            var appendtime = $('.endtime').val();
            window.location.href="/index.php?option=com_console&task=toAppSession&appstartime="+appstartime+'&appendtime='+appendtime;
        });
    });
    var picker = new Pikaday(
    {
        field: document.getElementById('datepicker'),
        firstDay: 1,
        minDate: new Date('2000-01-01'),
        maxDate: new Date('2020-12-31'),
        yearRange: [2000,2020],
    });
    var picker1 = new Pikaday(
    {
        field: document.getElementById('datepicker1'),
        firstDay: 1,
        minDate: new Date('2000-01-01'),
        maxDate: new Date('2020-12-31'),
        yearRange: [2000,2020]
    });

</script>
</body>
</html>
